The set function command is perhaps the most crucial command in data fitting. It is used to select a built-in fitting function or to enter a user-defined function. The following fitting functions are available:
NAME DESCRIPTION PARAMETERS REQUIRED ---- ----------- ------------------- straight Straight line (2 parameters) sine Sine series (N parameters) cosine Cosine series (N parameters) legendre Legendre series (N parameters) polynomial Power series (N parameters) gauss Gaussian series (3N parameters) expo Exponential series (2N parameters) user User-defined function (N parameters)
Assume a variable vector X and a parameter vector A then, the nonlinear gauss fitting function is a series of gaussians where
The nonlinear expo function is a series of exponentials where
For a user-defined function, the set function user will prompt for more input. The following input is related to the variable to fit. For purposes of clarity, let's say that we have to fit vectors X Y DY. This requires a fit function YFIT (the name is made from the dependent variable appended with FIT) and all the partial derivatives DYFITD1, DYFITD2, ..., DYFITDN taken with respect to the parameters n = 1,…N. All these functions are defined one per line as in the case of a macro until a stop is entered. Temporary variables are permitted. set function user actually defines a C-calculator mode macro that will be executed before each iteration of the fit. Therefore the complete C-calculator mode grammar is fully supported here. Temporary vectors can thus be used to speed up the calculation.
The C-calculator macro can be a simple call to a predefined procedure. When defined so, the parsing does not have to be done at each iteration, and a slightly faster process should result.
# read column 1, 2 and 3 of file "file" read file T:1 R:2 DR:3 # make a three parameter fit set parameter K 3 # this is a linear fit; use singular value decomposition set method svd_fit # enter my function set function user RFIT = K[1] + K[2]*T^0.5 + K[3]*T^1.5 DRFITD1 = 1 DRFITD2 = T^0.5 DRFITD3 = T^1.5 stop fit T R DR
The vector RFIT will contain the fitted function. The difference between the fit and real data can be obtained right away by defining a vector
let RDIFF = R - RFITthat can be plotted with respect to T.
The same thing is done for nonlinear fit with the exception that the partial derivatives of the function with respect to the parameters will contain reference to some parameter(s). (This is precisely the meaning of nonlinear here).
There is virtually no restriction on the number of parameters (memory is the sole limitation: set parameter command allocates a matrix of parameters X samples ). The only conditions are that a linear regression must have 2 parameters defined (this is obvious) and the built-in nonlinear functions must be modulo 3 for the series of gaussians and modulo 2 for the series of exponentials.
fit, set method, adjust, proc, auto